package logger

import (
	"container/list"
	"sync"
)

type Logger interface {
	Debug(value string)
	Debugf(formatter string, value ...interface{})
	Info(value string)
	Infof(formatter string, value ...interface{})
	Error(value string)
	Errorf(formatter string, value ...interface{})
	ErrorX(e error)
	Warring(value string)
	Warringf(formatter string, value ...interface{})
	Otherf(formatter string, value ...interface{})
	Otherf2(formatter string, value ...interface{})
	Other(value string)
	InitLog(configFile string)
	AutoDelete()
}

var instance *MyLogger
var once sync.Once

func GetLog() Logger {
	once.Do(func() {
		instance = &MyLogger{}
		instance.showLog = true
		instance.catch = list.New()
		go instance.write()
		instance.AutoDelete()
	})
	if instance.inited == false {
		instance.InitLog("")
	}
	return instance
}

func InitLog(file string) {
	GetLog().InitLog(file)
}

// Debug 调试日志
func Debug(value string) {
	GetLog().Debug(value)
}

// Debugf 格式化输出
func Debugf(formatter string, value ...interface{}) {
	GetLog().Debugf(formatter, value...)
}

// Info 信息日志
func Info(value string) {
	GetLog().Info(value)
}

// Infof 格式化输出
func Infof(formatter string, value ...interface{}) {
	GetLog().Infof(formatter, value...)
}

// Error 错误日志
func Error(value string) {
	GetLog().Error(value)
}

// Errorf 格式化输出
func Errorf(formatter string, value ...interface{}) {
	GetLog().Errorf(formatter, value...)
}

// ErrorX 输出错误日志
func ErrorX(e error) {
	GetLog().ErrorX(e)
}

// Warring  警告日志
func Warring(value string) {
	GetLog().Warring(value)
}

// Warringf 格式化输出
func Warringf(formatter string, value ...interface{}) {
	GetLog().Warringf(formatter, value...)
}

// Otherf 格式化输出
func Otherf(formatter string, value ...interface{}) {
	GetLog().Otherf(formatter, value...)
}

// Otherf2 格式化输出
func Otherf2(formatter string, value ...interface{}) {
	GetLog().Otherf2(formatter, value...)
}

// Other  其他日志
func Other(value string) {
	GetLog().Other(value)
}

// AutoDel 自动删除日志
func AutoDel() {
	GetLog().AutoDelete()
}
